/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.piwicode.bywordofmouth;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

/**
 *
 * @author pierre
 */
public class NamedObjects {

    public static <T extends NamedObject> ImmutableMap<String, T> index(Iterable<T> elements) {
        return Maps.uniqueIndex(elements, NameFunction.INSTANCE);
    }

    enum NameFunction implements Function<NamedObject, String> {

        INSTANCE;

        public String apply(NamedObject f) {
            return f.name();
        }
    }
}
